\documentclass[10pt,a4paper]{article}
\usepackage{graphicx}
\usepackage[english]{babel}
\usepackage{fullpage}
\usepackage{latexsym}
\usepackage{amssymb}
\usepackage[T1]{fontenc}
\usepackage[sc]{mathpazo}
\linespread{1.05}


\title{Applied Statistics \\ Study of journal paper}
\author{Mieke Hiltermann and Lotte van den Berg \\ Utrecht University}

\newcommand{\mco}{\mathcal{O}}
\newcommand{\mcg}{\mathcal{G}}
\newcommand{\mcv}{\mathcal{V}}
\newcommand{\mce}{\mathcal{E}}
\newcommand{\mcn}{\mathcal{N}}
\newcommand{\real}{\mathbb{R}}



\begin{document}

% \begin{titlepage}
% \maketitle 

% \tableofcontents

\section{Introduction}

Paper \textit{`An SPC case study on stabilizing syringe lengths'} van L.A. Franklin en S.N. Mukherjee. 
Over de langte van bepaalde spuitjes die gemaakt worden in een farmaceutisch bedrijf.

% ---------------------------------------
We chose to study the paper `An SPC case study on stabilizing syringe lengths' and we will critically check all the steps that are performed for this paper.\\
\\
This  case study is about the insertion of cartridges into plastic syringes and the electrical `tacking' of the  containment cap at a precisely determined length of the syringe at a pharmaceutical manufacturing company. This cap should not be `tacked' shorted then at a length of $4.290$ inch, and not longer then $4.980$ inch. With the help of SPC procedures the management wanted to improve the tacking operation. The length was targeted by a statistical quality specialist as a critical variable to be monitored by $\overline X$ and $R$ charts.\\

\section{Preliminaries}

In an attempt to check the capability of the process $35$ samples were taken from the `tacking'machine that was adjusted in what seemed its best possible position.\\
\\
The raw data that was received from theis procedure is stored in the file 'paperfranklindata1'. A capability study was undertaken to see if this process was capable and produce the desired length for the caps.\\
\\
A process capability analyst should consist of the following steps:
\begin{enumerate}
	\item a general inspection of the data: distribution of the data, outliers
	\item check wheter the process was statistically in-control
	\item remove the subgroups that were not in-control
	\item compute confidence intervals for the capability indices of interest
	\item use the confidence intervals to assess wheter the process is sufficiently capable
\end{enumerate}

This process is done in $R$ in the following way:
\begin{verbatim}
paper <- read.table("paperfranklindata1.txt")

#informal check for outliers, Box and Whisker Plot
boxplot(paper, horizontal = TRUE, main="Box-and-Whisker plot of initial data")

#Kernel density plot
plot(density(paper$V1),main="Kernel density estimate of initial data",col="red",lwd=3)

#Normal probability plot
qqnorm(paper$V1,main="Normal probability plot of initial data", pch=19,cex=1,fg="red")
qqline(paper$V1,lwd=3,col="blue",lty="dashed")

#Confidence levels
samplenumber <- rep(1:35, each=1)
paperdata <- qcc.groups(paper$V1, samplenumber)
paperqcc <- qcc(paperdata, type="xbar",spec.limits=c(4.920, 4.980))
process.capability(paperqcc, spec.limits=c(4.920, 4.980))
\end{verbatim}

The resulting graphics are:
\begin{figure*}[hbtp]  
\[
\begin{array}{ll}
\includegraphics[width=7cm]{paper-boxwhisker.jpg}&\includegraphics[width=7cm]{paper-densityplot.jpg}\\
\includegraphics[width=7cm]{paper-normalprobplot}&\includegraphics[width=7cm]{paper-pca.jpg}\\
\end{array}
\]
\caption{Process capability analysis}\label{fig:PCA}
\end{figure*}
From the Box and Whisker plot it is clear there are no outliers in the data, and all the data is within the limits of $4.290$ and $4.980$ inch. The density plot doesn't have a very nice left tail, but the right tail is very nice. The normal probability plot shows that the data in the upper quantiles have again a nice distribution, the data in the lower quantiles is again less nice distributed. The control charts seemed to be in-control so it is allowed to perform the capability study using the standard capability indices which are based on normality.\\
The capability study shows the process has a sample mean $\overline X=4.954$m this is close to the target value of $4.950$. The value obtained for $C_p=1.2$ and for $C_{pk}=1.02$. From this it was concluded that the process was minimally capable and could produce the desired length.\\

\section{Setting up the $\overline X$ and $R$ Control Charts}

To establish the control charts 15 samples each of size 5 were taken every 15 minutes this data can be seen in `paperfranklindataallekollommen.txt' (the first 15 rows).
First we computed the centers for the $R$ and the $\overline X$ charts.
\begin{verbatim}
> stats.R(paper2[1:15,2:6])
$statistics
    1     2     3     4     5     6     7     8     9    10    11    12    13 
0.014 0.031 0.042 0.042 0.014 0.018 0.016 0.020 0.056 0.036 0.016 0.032 0.012 
   14    15 
0.016 0.020 

$center
[1] 0.02566667

> stats.xbar(paper2[1:15,2:6])
$statistics
    1     2     3     4     5     6     7     8     9    10    11    12    13 
4.954 4.942 4.951 4.961 4.957 4.959 4.952 4.959 4.954 4.954 4.967 4.959 4.970 
   14    15 
4.963 4.970 

$center
[1] 4.958133
\end{verbatim}

So $E(X_i)=\mu==4.958133$ and $E(R_i)=0.02566667 $ for $i=1,\ldots,15 $, we also got the standard deviations:
\begin{verbatim}
> sd.xbar(paper2[1:15,2:6])
[1] 0.01162417
> sd.R(paper2[1:15,2:6])
[1] 0.01162417
\end{verbatim}
resulting in $\sigma=0.0116$ for this data set. Normally the upper and lower control limits for an $\overline X$ chart are set on 
\begin{eqnarray*}
(LCL,UCL)&=&(\mu-\frac{3\sigma}{\sqrt n},\, \mu+\frac{3\sigma}{\sqrt n})\\
&=&(4.942538,\, 4.973728).\\
\end{eqnarray*}
In the paper however they decided to take as 
\begin{eqnarray*}
(LCL,UCL)&=&(\mu-A_2(n) E(R_i),\, \mu+A_2(n) E(R_i))\\
&=&(4.958133-0.577*0.02566667,\, 4.958133+0.577*0.02566667)\\
&=&(4.9433, 4.9729)\\
\end{eqnarray*}
with $A_2$ a Control chart constant, dependent of the sample size. It is clear the change between the limits normally used and the limits used by the paper isn't very big. Therefore we chose to use limits that were used in the paper as well.\\

Normally the control limits used for the $R$ chart are:
\begin{eqnarray*}
LCL&=&D_{0.001}(n)\frac{E(R_i)}{d_2(n)}=0.199*\frac{E(R_i)}{2.326}=0.004049728\\
UCL&=&D_{0.999}(n)\frac{E(R_i)}{d_2(n)}=5.484*\frac{E(R_i)}{2.326}= 0.0605142.\\
\end{eqnarray*}
In the paper however they decided to take the control limits 
\begin{eqnarray*}
(D_3 E(R_i), D_4 E(R_i))&=&(0.000*0.02566667, 2.115* 0.02566667)\\
&=&(0.000, 0.0543).\\
\end{eqnarray*}
Again this difference isn't really big, and we again stick to the limits set by the paper.\\
%misschien een leuke toevoeging om ook R en X charts te maken met de 'normale'waarden...

From this data R is able to make an $\overline X$ chart and an $R$ chart see figure \ref{fig:control}\\
\begin{figure*}[hbtp]
\includegraphics[width=7cm]{paper-xbar.jpg} \includegraphics[width=7cm]{paper-R.jpg}\\
\caption{Control charts}\label{fig:control}
\end{figure*}
\begin{verbatim}
paper2 <- read.table("paperfranklindataallekollommen.txt")
paperqccX1 <-qcc(paper2[1:15,2:6], type="xbar", center=4.958, limits=c(4.9433,4.9729))
paperqccR1 <-qcc(paper2[1:15,2:6], type="R", center=0.02567, limits=c(0.0,0.0543))
\end{verbatim}

These charts show thet the process is already out of control in both the center (with a distinctly upward trend) and in variation as well. Proper application of SPC precedures would have correction action immediately being taken, as a search begun to try to locate the cause of the problem, and new control limits being constructed. 
%Dit is allemaal letterlijke tekst, moeten we zo stukken eruit halen om een lopend verhaal te houden of zouden we echt alleen de berekeningen na hoeven doen?

\section{The Process Monitoring and Adjustment Stages}

Samples of size 5 were still taken every 15 min. but they were only plotted when again 15 samples were taken. This plot was made with the data of the second 15 samples but with the specification limits from the first set of 15 points. Resulting in figure \ref{fig:control2}
\begin{figure*}[hbtp]
\includegraphics[width=7cm]{paper-xbar2.jpg} \includegraphics[width=7cm]{paper-R2.jpg}\\
\caption{Control charts}\label{fig:control2}
\end{figure*}
\begin{verbatim}
paperqccX2 <-qcc(paper2[16:32,2:6], type="xbar", center=4.958, limits=c(4.9433,4.9729))
paperqccR2 <-qcc(paper2[16:32,2:6], type="R", center=0.02567, limits=c(0.0,0.0543))
\end{verbatim}
These charts show clearly the center to be out-of-control and an average length which is far greater then desired. The technician was called in to adjust properly. After the first adjustment the next sample was aagain beyand he upper control limit for the $\overline X$ chart. The technician was recalled to readjust the machine, this again did not help. The samples taken after those 2 adjustments are in row 31 and 32 of the dataset. This are also the last two points in the graphs of figure \ref{fig:control2}. After the technician had tried a third time both the $\overline X$ chart and the $R$ chart were within the control limits. So they went on sampling every 15 minutes.


\section{Production Run and the Persistent Statistical Quality Specialist}

After 15 additional samples were taken those were plotted again, shown in figure \ref{fig:control3}.
\begin{figure*}[hbtp]
\includegraphics[width=7cm]{paper-xbar3.jpg} \includegraphics[width=7cm]{paper-R3.jpg}\\
\caption{Control charts}\label{fig:control3}
\end{figure*}
\begin{verbatim}
paperqccX3 <-qcc(paper2[33:47,2:6], type="xbar", center=4.958, limits=c(4.9433,4.9729))
paperqccR3 <-qcc(paper2[33:47,2:6], type="R", center=0.02567, limits=c(0.0,0.0543))
\end{verbatim}

From this these charts a statistical quality specialies made the following conclusions: the original 15 points used to define $\overline X$ and the $R$ charts showed a process not under statistical control, but the last 15 points also showed a process not under statistical control. 
%moeten wij dit nog een keer bevestigen?
%waarom zijn de eerste 15 punten niet in-control?

But the variation of the points have been reduced, almost all the last 15 points are beneath the center line. This is a good thing withing statistical control.

%uitleggen dat de punten van de chart oranje worden als meer dan 6 opeen volgende punten boven of onder de centerline liggen. Zouden we dit ook op 8 kunnen zetten (dan zijn we consistent met de paper)



\section{"The Butler Did It!"}
%zouden we deze explanation ook over moeten nemen?



%DEZE IS WEL HEEL VERSCHILLEND!
\begin{figure*}[hbtp]
\begin{center}
\includegraphics[width=7cm]{paper-PCAlaatste15.jpg}
\caption{Final capability analysis}\label{fig:finalcap}
\end{center}
\end{figure*}

\section{Conclusion and Lessons}

\end{document}